Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

enhancement: revamp GraphQL query generation #1450

Closed
wants to merge 1 commit into from

Conversation

deekerno
Copy link
Contributor

@deekerno deekerno commented Nov 2, 2023

Description

This PR rewrites the indexer service's GraphQL query resolution layer.

The following breaking changes have been made:

  • If annotated with the @queryable directive, each entity type has two queries generated for it which are the entry points for querying the indexer service:
    -- a query returning a singular object record, which take at most one argument that matches to a field in the entity. The chosen field must be annotated with the @search and @unique directives.
    -- a query returning a Connection for the entity as described in the GraphQL Cursor Connections specification.
  • Input objects are now programmatically per type; this means that there is no longer general filtering and sorting behavior.
    -- A connection query will allow for the use of a sort input object as long as at least one of its entity's fields is sortable.
    -- A connection query will allow for the use of a filter input object as long as at least one of its entity's fields is marked with the @filter directive.
  • Query responses are now spec-compliant with regards to the Response Format section of the GraphQL specification.
  • Offset-based pagination has been retired in favor of cursor-based pagination.
    -- Paginated queries require a limit (by using the first keyword) and a sort order (by using the order keyword). Requesting the next or previous "page" can be done by passing a value from a cursor field from the response as a value for either the after or before keywords, respectively.

In addition to the above, the following non-breaking changes and fixes have been made:

  • Adds support for query variables.
  • Adds support for the @skip and @include directives as required by the relevant section of the GraphQL specification.
  • Adds support for connection types; these are automatically generated for an entity.
  • Adds a @filter directive for fields to denote which fields should be used for filtering connection queries.
  • Adds support for executing multiple operations in one request.
  • Adds proper introspection data generation for logical operators with filter input objects.
  • Adjusts query string generation to use Display traits.
    -- Queries are modeled through types and then converted to strings at the end.
  • Adjusts hello-world example to be a simple explorer of blocks with lists of transactions.
  • Cleans up organization of fuel-indexer-graphql module.
  • Fixes querying for list type fields on an object.
  • Fixes issue with database joins not being in correct sorted order.
  • Moves introspection type generation from dynamic.rs to the GraphQL schema parsing step.
  • Reduces use of format!() calls in query generation.

Testing steps

First, build the Fuel explorer example; you can use bash scripts/utils/build_modules.bash to build all examples. Then, start the Fuel explorer example with the service (be sure to adjust the Postgres details if they differ from the following command):

cargo run -p fuel-indexer -- run --fuel-node-host beta-4.fuel.network --fuel-node-port 80 --database postgres --postgres-host 127.0.0.1 --postgres-port 5432 --postgres-user postgres --postgres-password 'my-secret' --postgres-database 'postgres'

Examples coming soon...

Notes

Yes, this PR is quite large. However, given that the block explorer will be served by an indexer backend, we needed to support as much GraphQL functionality as we possibly can; we do not have the luxury of enshrining certain types and queries as part of our code so we need to be able to support anything that a user may feasibly create.

@deekerno deekerno added documentation Improvements or additions to documentation P: High work in progress labels Nov 2, 2023
@deekerno deekerno self-assigned this Nov 2, 2023
@deekerno deekerno force-pushed the deekerno/revamp-gql-query-generation branch 5 times, most recently from f82f1c4 to f1e24fc Compare November 7, 2023 21:01
Copy link
Contributor

@ra0x3 ra0x3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deekerno

  • Round 1 finished.
  • I just left comments on some high level maintainability stuff - in general I think we want to avoid format! here as much as possible and abstract these (what are effectively just Strings into structs and functions). Seems a bit overkill but there's a lot of business logic in this queries module
  • Could you also update Testing Steps with instructions on how I would test the block explorer?
    • We will probably have some non-indexer folks test the queries as well

packages/fuel-indexer-graphql/src/query.rs Outdated Show resolved Hide resolved
packages/fuel-indexer-graphql/src/query.rs Outdated Show resolved Hide resolved
packages/fuel-indexer-graphql/src/query.rs Outdated Show resolved Hide resolved
@deekerno deekerno force-pushed the deekerno/revamp-gql-query-generation branch from 0db936f to 3237f10 Compare November 9, 2023 19:32
@deekerno deekerno force-pushed the deekerno/revamp-gql-query-generation branch from 920726b to 209936f Compare November 27, 2023 05:10
@deekerno deekerno force-pushed the deekerno/revamp-gql-query-generation branch 2 times, most recently from feb4a43 to 35880f9 Compare December 4, 2023 02:33
@deekerno deekerno force-pushed the deekerno/revamp-gql-query-generation branch 3 times, most recently from dfbd26c to ae34b45 Compare December 13, 2023 23:07
@deekerno deekerno linked an issue Dec 14, 2023 that may be closed by this pull request
5 tasks
@deekerno deekerno added big breaking This is a change that will break some component of the project once merged to origin/develop labels Dec 14, 2023
@deekerno deekerno force-pushed the deekerno/revamp-gql-query-generation branch 4 times, most recently from 43a4025 to f1f6005 Compare December 15, 2023 00:48
@deekerno deekerno marked this pull request as ready for review December 15, 2023 20:02
@deekerno deekerno requested a review from lostman as a code owner December 15, 2023 20:02
@deekerno deekerno force-pushed the deekerno/revamp-gql-query-generation branch from f1f6005 to 06c41a7 Compare December 15, 2023 21:48
@deekerno deekerno removed the documentation Improvements or additions to documentation label Dec 15, 2023
@deekerno deekerno closed this Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
big breaking This is a change that will break some component of the project once merged to origin/develop P: High
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate web server, GraphQL layer, and data layer
2 participants